'''My today time'''
import time
from bcapi import BCAPI
from bcuser import get_current_user_account 

def content(handler, account=get_current_user_account()):
    buffer = '<h2>' + account.username + '</h2>'

    time_list = gettime(account)

    total_time = 0.0
    for pid in time_list:
        total_time += time_list[pid]
        buffer += pid + ' : ' + str(time_list[pid])

    buffer += '<p>total : %f' % total_time

    return str(buffer)


def css(handler):
    return '' 

def gettime(account):
    '''Get time'''
    bc = BCAPI(account)
    me = bc.me()

    today = time.localtime()
    q_from = '%d%02d%02d' % (today[0], today[1], today[2])
    subject_id = me.find('id').text

    q = {
        'from': q_from,
        'subject_id': subject_id,
    }

    bc.set_nocache(True)
    entries = bc.report(q)

    time_list = {}
    for entry in entries:
        time_list[entry.find('project-id').text] = float(entry.find('hours').text)

    return time_list
